
<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Leo’s Cheat Sheet &#8212; Leo 6.7.2 documentation</title>
    <link rel="stylesheet" type="text/css" href="_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="_static/classic.css" />
    <link rel="stylesheet" type="text/css" href="_static/custom.css" />
    
    <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
    <script src="_static/jquery.js"></script>
    <script src="_static/underscore.js"></script>
    <script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
    <script src="_static/doctools.js"></script>
    <script src="_static/sphinx_highlight.js"></script>
    
    <script src="_static/sidebar.js"></script>
    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Slides" href="slides.html" />
    <link rel="prev" title="FAQ" href="FAQ.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="slides.html" title="Slides"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="FAQ.html" title="FAQ"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="leo_toc.html">Leo 6.7.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="toc-more-links.html" accesskey="U">More Leo Links</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Leo’s Cheat Sheet</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="leo-s-cheat-sheet">
<h1>Leo’s Cheat Sheet<a class="headerlink" href="#leo-s-cheat-sheet" title="Permalink to this heading">¶</a></h1>
<p>This Cheat Sheet contains a summary of many of Leo’s important features.
<strong>Important</strong>: The easiest way to find documentation is to search LeoDocs.leo.</p>
<div class="contents local topic" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#key-bindings" id="id2">Key bindings</a></p>
<ul>
<li><p><a class="reference internal" href="#selecting-outline-nodes" id="id3">Selecting outline nodes</a></p></li>
<li><p><a class="reference internal" href="#moving-outline-nodes" id="id4">Moving outline nodes</a></p></li>
<li><p><a class="reference internal" href="#moving-the-cursor" id="id5">Moving the cursor</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#executing-minibuffer-commands" id="id6">Executing minibuffer commands</a></p></li>
<li><p><a class="reference internal" href="#frequently-used-commands" id="id7">Frequently used commands</a></p></li>
<li><p><a class="reference internal" href="#gathering-find-commands" id="id8">Gathering find commands</a></p></li>
<li><p><a class="reference internal" href="#leo-directives" id="id9">Leo directives</a></p></li>
<li><p><a class="reference internal" href="#settings" id="id10">Settings</a></p></li>
<li><p><a class="reference internal" href="#node-types" id="id11">Node types</a></p></li>
<li><p><a class="reference internal" href="#notable-plugins" id="id12">Notable Plugins</a></p></li>
<li><p><a class="reference internal" href="#external-files-file-nodes" id="id13">External files (&#64;&lt;file&gt; nodes)</a></p></li>
<li><p><a class="reference internal" href="#sections" id="id14">Sections</a></p></li>
<li><p><a class="reference internal" href="#scripting" id="id15">Scripting</a></p>
<ul>
<li><p><a class="reference internal" href="#pre-defined-symbols" id="id16">Pre-defined symbols</a></p></li>
<li><p><a class="reference internal" href="#leoapp-class" id="id17">LeoApp class</a></p></li>
<li><p><a class="reference internal" href="#commands-class" id="id18">Commands class</a></p></li>
<li><p><a class="reference internal" href="#undoing-commands" id="id19">Undoing commands</a></p>
<ul>
<li><p><a class="reference internal" href="#undoably-changing-body-text" id="id20">Undoably changing body text</a></p></li>
<li><p><a class="reference internal" href="#undoably-changing-multiple-nodes" id="id21">Undoably changing multiple nodes</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#vnode-class" id="id22">VNode class</a></p></li>
<li><p><a class="reference internal" href="#position-class" id="id23">Position class</a></p></li>
<li><p><a class="reference internal" href="#leo-core-leoglobals-module" id="id24">leo.core.leoGlobals module</a></p></li>
<li><p><a class="reference internal" href="#test-driven-development" id="id25">Test driven development</a></p></li>
<li><p><a class="reference internal" href="#performance-gotchas" id="id26">Performance gotchas</a></p></li>
<li><p><a class="reference internal" href="#prompting-for-command-arguments" id="id27">Prompting for command arguments</a></p>
<ul>
<li><p><a class="reference internal" href="#example-1-prompt-for-one-arg" id="id28">Example 1: Prompt for one arg</a></p></li>
<li><p><a class="reference internal" href="#example-2-prompt-for-2-args" id="id29">Example 2: Prompt for 2 args</a></p></li>
<li><p><a class="reference internal" href="#example-3-prompt-for-3-args" id="id30">Example 3: Prompt for 3 args</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#naming-conventions-in-leo-s-core" id="id31">Naming conventions in Leo’s core</a></p>
<ul>
<li><p><a class="reference internal" href="#official-ivars" id="id32">Official ivars</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#widgets-and-wrappers" id="id33">Widgets and wrappers</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#command-line-options" id="id34">Command-line options</a></p></li>
<li><p><a class="reference internal" href="#learning-to-be-a-leo-developer" id="id35">Learning to be a Leo developer</a></p>
<ul>
<li><p><a class="reference internal" href="#code-academy" id="id36">Code academy</a></p>
<ul>
<li><p><a class="reference internal" href="#ca-ua-s" id="id37">CA: uA’s</a></p></li>
<li><p><a class="reference internal" href="#ca-icons" id="id38">CA: icons</a></p></li>
<li><p><a class="reference internal" href="#ca-using-git" id="id39">CA: using git</a></p></li>
<li><p><a class="reference internal" href="#ca-finding-nodes-with-c-clonefindbypredicate" id="id40">CA: finding nodes with c.cloneFindByPredicate</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#leo-university" id="id41">Leo University</a></p></li>
<li><p><a class="reference internal" href="#architecture" id="id42">Architecture</a></p></li>
</ul>
</li>
</ul>
</div>
<section id="key-bindings">
<h2><a class="toc-backref" href="#id2">Key bindings</a><a class="headerlink" href="#key-bindings" title="Permalink to this heading">¶</a></h2>
<section id="selecting-outline-nodes">
<h3><a class="toc-backref" href="#id3">Selecting outline nodes</a><a class="headerlink" href="#selecting-outline-nodes" title="Permalink to this heading">¶</a></h3>
<p>When focus is in the outline pane:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Right</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">expand</span><span class="o">-</span><span class="ow">and</span><span class="o">-</span><span class="n">go</span><span class="o">-</span><span class="n">right</span><span class="p">)</span>
<span class="n">Left</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">contract</span><span class="o">-</span><span class="ow">or</span><span class="o">-</span><span class="n">go</span><span class="o">-</span><span class="n">left</span><span class="p">)</span>
<span class="n">Up</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">goto</span><span class="o">-</span><span class="n">prev</span><span class="o">-</span><span class="n">visible</span><span class="p">)</span>
<span class="n">Down</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">goto</span><span class="o">-</span><span class="nb">next</span><span class="o">-</span><span class="n">visible</span><span class="p">)</span>
</pre></div>
</div>
<p>Regardless of focus:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Alt</span><span class="o">-</span><span class="n">Home</span> <span class="p">(</span><span class="n">goto</span><span class="o">-</span><span class="n">first</span><span class="o">-</span><span class="n">visible</span><span class="o">-</span><span class="n">node</span><span class="p">)</span>
<span class="n">Alt</span><span class="o">-</span><span class="n">End</span> <span class="p">(</span><span class="n">goto</span><span class="o">-</span><span class="n">last</span><span class="o">-</span><span class="n">visible</span><span class="o">-</span><span class="n">node</span><span class="p">)</span>
<span class="n">Alt</span><span class="o">-</span><span class="n">Right</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">expand</span><span class="o">-</span><span class="ow">and</span><span class="o">-</span><span class="n">go</span><span class="o">-</span><span class="n">right</span><span class="p">)</span>
<span class="n">Alt</span><span class="o">-</span><span class="n">Left</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">contract</span><span class="o">-</span><span class="ow">or</span><span class="o">-</span><span class="n">go</span><span class="o">-</span><span class="n">left</span><span class="p">)</span>
<span class="n">Alt</span><span class="o">-</span><span class="n">Up</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">goto</span><span class="o">-</span><span class="n">prev</span><span class="o">-</span><span class="n">visible</span><span class="p">)</span>
<span class="n">Alt</span><span class="o">-</span><span class="n">Down</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">goto</span><span class="o">-</span><span class="nb">next</span><span class="o">-</span><span class="n">visible</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="moving-outline-nodes">
<h3><a class="toc-backref" href="#id4">Moving outline nodes</a><a class="headerlink" href="#moving-outline-nodes" title="Permalink to this heading">¶</a></h3>
<p>When focus is in the outline:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Shift</span><span class="o">-</span><span class="n">Down</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">down</span><span class="p">)</span>
<span class="n">Shift</span><span class="o">-</span><span class="n">Left</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">left</span><span class="p">)</span>
<span class="n">Shift</span><span class="o">-</span><span class="n">Right</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">right</span><span class="p">)</span>
<span class="n">Shift</span><span class="o">-</span><span class="n">Up</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">up</span><span class="p">)</span>
</pre></div>
</div>
<p>Regardless of focus:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Alt</span><span class="o">-</span><span class="n">Shift</span><span class="o">-</span><span class="n">Down</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">down</span><span class="p">)</span>
<span class="n">Alt</span><span class="o">-</span><span class="n">Shift</span><span class="o">-</span><span class="n">Left</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">left</span><span class="p">)</span>
<span class="n">Alt</span><span class="o">-</span><span class="n">Shift</span><span class="o">-</span><span class="n">Right</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">right</span><span class="p">)</span>
<span class="n">Alt</span><span class="o">-</span><span class="n">Shift</span><span class="o">-</span><span class="n">Up</span><span class="o">-</span><span class="n">arrow</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">up</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">D</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">down</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">L</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">left</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">R</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">right</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">U</span> <span class="p">(</span><span class="n">move</span><span class="o">-</span><span class="n">outline</span><span class="o">-</span><span class="n">up</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="moving-the-cursor">
<h3><a class="toc-backref" href="#id5">Moving the cursor</a><a class="headerlink" href="#moving-the-cursor" title="Permalink to this heading">¶</a></h3>
<p>When focus is in any of Leo’s text panes (body pane, log pane, headlines):</p>
<blockquote>
<div><table class="docutils align-default">
<colgroup>
<col style="width: 45%" />
<col style="width: 55%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><strong>Key</strong></p></td>
<td><p><strong>Move Cursor</strong></p></td>
</tr>
<tr class="row-even"><td><p>Arrow keys</p></td>
<td><p>one character</p></td>
</tr>
<tr class="row-odd"><td><p>Ctrl-LeftArrow</p></td>
<td><p>back one word</p></td>
</tr>
<tr class="row-even"><td><p>Ctrl-RightArrow</p></td>
<td><p>forward one word</p></td>
</tr>
<tr class="row-odd"><td><p>Home</p></td>
<td><p>beginning of line</p></td>
</tr>
<tr class="row-even"><td><p>End</p></td>
<td><p>end of line</p></td>
</tr>
<tr class="row-odd"><td><p>Ctrl-Home</p></td>
<td><p>beginning of the body</p></td>
</tr>
<tr class="row-even"><td><p>Ctrl-End</p></td>
<td><p>end of body</p></td>
</tr>
<tr class="row-odd"><td><p>PageDown</p></td>
<td><p>down one page</p></td>
</tr>
<tr class="row-even"><td><p>PageUp</p></td>
<td><p>up one page</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>Adding the Shift key modifier to any of the keys above moves the cursor and extends the selected text.</p>
</section>
</section>
<section id="executing-minibuffer-commands">
<h2><a class="toc-backref" href="#id6">Executing minibuffer commands</a><a class="headerlink" href="#executing-minibuffer-commands" title="Permalink to this heading">¶</a></h2>
<p>Alt-X puts focus in the minibuffer. Ctrl-G escapes from the minibuffer.</p>
<p>Once there, you can use tab completion to reduce typing. For example, &lt;Alt-X&gt;open&lt;tab&gt; shows all commands that start with open.</p>
<p>Hit &lt;Enter&gt; to run a complete command.</p>
<p>Ctrl-P (repeat-complex-command) repeat the last command entered from the minibuffer.</p>
<p>Leo maintains a <strong>command history list</strong> of all minibuffer commands you have entered.</p>
<p>When focus is in the minibuffer, UpArrow shows the previous minibuffer command, and DnArrow show the commands before that.</p>
<p>The body text of an &#64;data history-list <em>setting node</em> preloads commands into the command history list, ignoring lines starting with ‘#’. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">run</span><span class="o">-</span><span class="n">pylint</span>
<span class="n">beautify</span><span class="o">-</span><span class="n">tree</span>
<span class="n">cff</span>
<span class="n">sort</span><span class="o">-</span><span class="n">lines</span>
<span class="c1"># show-data</span>
<span class="n">check</span><span class="o">-</span><span class="n">clones</span>
<span class="n">expand</span><span class="o">-</span><span class="n">log</span><span class="o">-</span><span class="n">pane</span>
<span class="n">contract</span><span class="o">-</span><span class="n">log</span><span class="o">-</span><span class="n">pane</span>
</pre></div>
</div>
</section>
<section id="frequently-used-commands">
<h2><a class="toc-backref" href="#id7">Frequently used commands</a><a class="headerlink" href="#frequently-used-commands" title="Permalink to this heading">¶</a></h2>
<p>For much more information, see the <a class="reference external" href="commands.html">Commands Reference</a>.</p>
<p>Copy/Paste (text):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Ctrl</span><span class="o">-</span><span class="n">C</span> <span class="p">(</span><span class="n">copy</span><span class="o">-</span><span class="n">text</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">K</span> <span class="p">(</span><span class="n">kill</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">V</span> <span class="p">(</span><span class="n">paste</span><span class="o">-</span><span class="n">text</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">X</span> <span class="p">(</span><span class="n">cut</span><span class="o">-</span><span class="n">text</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">Y</span> <span class="p">(</span><span class="n">yank</span><span class="p">)</span>
<span class="n">Alt</span><span class="o">-</span><span class="n">Y</span>  <span class="p">(</span><span class="n">yank</span><span class="o">-</span><span class="n">pop</span><span class="p">)</span>
<span class="n">kill</span><span class="o">-...</span>
</pre></div>
</div>
<p>Files:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Ctrl</span><span class="o">-</span><span class="n">N</span> <span class="p">(</span><span class="n">new</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">O</span> <span class="p">(</span><span class="nb">open</span><span class="o">-</span><span class="n">outline</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">S</span> <span class="p">(</span><span class="n">save</span><span class="o">-</span><span class="n">file</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">Q</span> <span class="p">(</span><span class="n">exit</span><span class="o">-</span><span class="n">leo</span><span class="p">)</span>
</pre></div>
</div>
<p>Focus:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Alt</span><span class="o">-</span><span class="n">T</span> <span class="p">(</span><span class="n">focus</span><span class="o">-</span><span class="n">to</span><span class="o">-</span><span class="n">tree</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">T</span> <span class="p">(</span><span class="n">toggle</span><span class="o">-</span><span class="n">active</span><span class="o">-</span><span class="n">pane</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">Tab</span> <span class="p">(</span><span class="n">tab</span><span class="o">-</span><span class="n">cycle</span><span class="o">-</span><span class="nb">next</span><span class="p">)</span>
</pre></div>
</div>
<p>Help:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Alt</span><span class="o">-</span><span class="mi">0</span> <span class="p">(</span><span class="n">vr</span><span class="o">-</span><span class="n">toggle</span><span class="p">)</span>
<span class="n">F1</span> <span class="p">(</span><span class="n">help</span><span class="p">)</span>
<span class="n">F11</span> <span class="p">(</span><span class="n">help</span><span class="o">-</span><span class="k">for</span><span class="o">-</span><span class="n">command</span><span class="p">)</span>
<span class="n">F12</span> <span class="p">(</span><span class="n">help</span><span class="o">-</span><span class="k">for</span><span class="o">-</span><span class="n">python</span><span class="p">)</span>
<span class="nb">print</span><span class="o">-</span><span class="n">bindings</span>
<span class="nb">print</span><span class="o">-</span><span class="n">settings</span>
<span class="n">help</span><span class="o">-</span><span class="k">for</span><span class="o">-...</span>
</pre></div>
</div>
<p>Find/Replace:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Ctrl</span><span class="o">-</span><span class="n">F</span> <span class="p">(</span><span class="n">search</span><span class="o">-</span><span class="k">with</span><span class="o">-</span><span class="n">present</span><span class="o">-</span><span class="n">options</span><span class="p">)</span>
<span class="n">Shift</span><span class="o">-</span><span class="n">Ctrl</span><span class="o">-</span><span class="n">R</span> <span class="p">(</span><span class="n">replace</span><span class="o">-</span><span class="n">string</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">minus</span> <span class="p">(</span><span class="n">replace</span><span class="o">-</span><span class="n">then</span><span class="o">-</span><span class="n">find</span><span class="p">)</span>
<span class="n">F3</span> <span class="p">(</span><span class="n">find</span><span class="o">-</span><span class="nb">next</span><span class="p">)</span>
<span class="n">F2</span> <span class="p">(</span><span class="n">find</span><span class="o">-</span><span class="n">previous</span><span class="p">)</span>
</pre></div>
</div>
<p>Minibuffer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Alt</span><span class="o">-</span><span class="n">X</span> <span class="p">(</span><span class="n">full</span><span class="o">-</span><span class="n">command</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">G</span> <span class="p">(</span><span class="n">keyboard</span><span class="o">-</span><span class="n">quit</span><span class="p">)</span>
<span class="n">Tab</span> <span class="p">(</span><span class="ow">not</span> <span class="n">a</span> <span class="n">command</span><span class="p">,</span> <span class="n">completes</span> <span class="n">typing</span><span class="p">)</span>
</pre></div>
</div>
<p>Nodes:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Ctrl</span><span class="o">-</span><span class="n">I</span> <span class="ow">or</span> <span class="n">Insert</span> <span class="p">(</span><span class="n">insert</span><span class="o">-</span><span class="n">node</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">H</span> <span class="p">(</span><span class="n">edit</span><span class="o">-</span><span class="n">headline</span><span class="p">)</span>
<span class="o">&lt;</span><span class="n">Return</span><span class="o">&gt;</span> <span class="p">(</span><span class="n">when</span> <span class="n">editing</span> <span class="n">a</span> <span class="n">headline</span><span class="p">)</span> <span class="p">(</span><span class="n">end</span><span class="o">-</span><span class="n">edit</span><span class="o">-</span><span class="n">headline</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">Shift</span><span class="o">-</span><span class="n">C</span> <span class="p">(</span><span class="n">copy</span><span class="o">-</span><span class="n">node</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">Shift</span><span class="o">-</span><span class="n">X</span> <span class="p">(</span><span class="n">cut</span><span class="o">-</span><span class="n">node</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">Shift</span><span class="o">-</span><span class="n">V</span> <span class="p">(</span><span class="n">paste</span><span class="o">-</span><span class="n">node</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="p">{</span> <span class="p">(</span><span class="n">promote</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="p">}</span> <span class="p">(</span><span class="n">demote</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">M</span> <span class="p">(</span><span class="n">mark</span><span class="p">)</span>
</pre></div>
</div>
<p>Undo:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Ctrl</span><span class="o">-</span><span class="n">Z</span> <span class="p">(</span><span class="n">undo</span><span class="p">)</span>
<span class="n">Ctrl</span><span class="o">-</span><span class="n">Shift</span><span class="o">-</span><span class="n">Z</span> <span class="p">(</span><span class="n">redo</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="gathering-find-commands">
<h2><a class="toc-backref" href="#id8">Gathering find commands</a><a class="headerlink" href="#gathering-find-commands" title="Permalink to this heading">¶</a></h2>
<p>The <strong>clone find</strong> commands, cfa and cff,  move clones of all nodes matching the search pattern under a single <strong>organizer node</strong>, created as the last top-level node. <strong>Flattened</strong> searches put all nodes as direct children of the organizer node:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cfa</span>     <span class="n">clone</span><span class="o">-</span><span class="n">find</span><span class="o">-</span><span class="nb">all</span>
<span class="n">cff</span>     <span class="n">clone</span><span class="o">-</span><span class="n">find</span><span class="o">-</span><span class="nb">all</span><span class="o">-</span><span class="n">flattened</span>
</pre></div>
</div>
<p>The <strong>clone-marked</strong> commands move clones of all marked nodes under an organizer node. Especially useful for gathering nodes by hand:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cfam</span>    <span class="n">clone</span><span class="o">-</span><span class="n">find</span><span class="o">-</span><span class="n">marked</span>
<span class="n">cffm</span>    <span class="n">clone</span><span class="o">-</span><span class="n">find</span><span class="o">-</span><span class="n">flattened</span><span class="o">-</span><span class="n">marked</span>
</pre></div>
</div>
</section>
<section id="leo-directives">
<h2><a class="toc-backref" href="#id9">Leo directives</a><a class="headerlink" href="#leo-directives" title="Permalink to this heading">¶</a></h2>
<p>Directives starting with ‘&#64; in the leftmost column</p>
<p>See the <a class="reference external" href="directives.html">Directives reference</a> for full details:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">@</span>                       <span class="c1"># starts doc part</span>
<span class="nd">@c</span>                      <span class="c1"># ends doc part</span>
<span class="nd">@color</span>
<span class="nd">@doc</span>                    <span class="c1"># starts doc part</span>
<span class="nd">@killcolor</span>
<span class="nd">@nocolor</span>
<span class="nd">@language</span> <span class="n">python</span>
<span class="nd">@language</span> <span class="n">c</span>
<span class="nd">@language</span> <span class="n">rest</span>          <span class="c1"># restructured text</span>
<span class="nd">@language</span> <span class="n">plain</span>         <span class="c1"># plain text: no syntax coloring.</span>
<span class="nd">@lineending</span> <span class="n">lineending</span>
<span class="nd">@nosearch</span>               <span class="c1"># suppress searching for cff &amp; cfa commands.</span>
<span class="nd">@pagewidth</span> <span class="mi">100</span>
<span class="nd">@tabwidth</span> <span class="o">-</span><span class="mi">4</span>            <span class="c1"># use spaces</span>
<span class="nd">@tabwidth</span> <span class="mi">8</span>             <span class="c1"># use tabs</span>
<span class="nd">@nowrap</span>
<span class="nd">@wrap</span>
</pre></div>
</div>
<p>Leading whitespace is allowed (and significant) for:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@all</span>
<span class="nd">@others</span>
</pre></div>
</div>
</section>
<section id="settings">
<h2><a class="toc-backref" href="#id10">Settings</a><a class="headerlink" href="#settings" title="Permalink to this heading">¶</a></h2>
<p>For documentation see node: “About this file” in leoSettings.leo:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Command</span> <span class="n">history</span><span class="p">:</span>    <span class="nd">@history</span><span class="o">-</span><span class="nb">list</span>
<span class="n">Key</span> <span class="n">bindings</span><span class="p">:</span>       <span class="nd">@shortcuts</span>
<span class="n">Visual</span> <span class="n">settings</span><span class="p">:</span>    <span class="nd">@data</span> <span class="n">qt</span><span class="o">-</span><span class="n">gui</span><span class="o">-</span><span class="n">plugin</span><span class="o">-</span><span class="n">style</span><span class="o">-</span><span class="n">sheet</span>
<span class="n">Enabling</span> <span class="n">plugins</span><span class="p">:</span>   <span class="nd">@enabled</span><span class="o">-</span><span class="n">plugins</span>
</pre></div>
</div>
<p>To disable a binding for a key, bind it to do-nothing:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">do</span><span class="o">-</span><span class="n">nothing</span> <span class="o">=</span> <span class="n">Insert</span>
</pre></div>
</div>
<p>This overrides the following default binding in leoSettings.leo:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">insert</span><span class="o">-</span><span class="n">node</span> <span class="o">=</span> <span class="n">Insert</span>
</pre></div>
</div>
</section>
<section id="node-types">
<h2><a class="toc-backref" href="#id11">Node types</a><a class="headerlink" href="#node-types" title="Permalink to this heading">¶</a></h2>
<p>Supported by Leo’s core:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@chapter</span>
<span class="nd">@rst</span><span class="p">,</span> <span class="nd">@rst</span><span class="o">-</span><span class="n">no</span><span class="o">-</span><span class="n">head</span><span class="p">,</span> <span class="nd">@rst</span><span class="o">-</span><span class="n">ignore</span><span class="p">,</span> <span class="nd">@rst</span><span class="o">-</span><span class="n">ignore</span><span class="o">-</span><span class="n">tree</span>
<span class="nd">@settings</span>
<span class="nd">@url</span>
</pre></div>
</div>
<p>Within &#64;settings trees:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@bool</span><span class="p">,</span> <span class="nd">@buttons</span><span class="p">,</span> <span class="nd">@color</span><span class="p">,</span> <span class="nd">@commands</span>
<span class="nd">@directory</span><span class="p">,</span> <span class="nd">@encoding</span>
<span class="nd">@enabled</span><span class="o">-</span><span class="n">plugins</span><span class="p">,</span> <span class="nd">@float</span><span class="p">,</span> <span class="nd">@font</span><span class="p">,</span>
<span class="nd">@history</span><span class="o">-</span><span class="nb">list</span><span class="p">,</span> <span class="nd">@int</span>
<span class="nd">@menus</span><span class="p">,</span> <span class="nd">@menu</span><span class="p">,</span> <span class="nd">@menuat</span><span class="p">,</span> <span class="nd">@item</span>
<span class="nd">@openwith</span><span class="p">,</span> <span class="nd">@path</span><span class="p">,</span> <span class="nd">@shortcuts</span><span class="p">,</span> <span class="nd">@string</span>
</pre></div>
</div>
<p>Supported by plugins:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">bookmarks</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>       <span class="nd">@bookmarks</span><span class="p">,</span> <span class="nd">@bookmark</span>
<span class="n">at_folder</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>       <span class="nd">@folder</span>
<span class="n">at_produce</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>      <span class="nd">@produce</span>
<span class="n">at_view</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>         <span class="nd">@clip</span><span class="p">,</span> <span class="nd">@strip</span><span class="p">,</span> <span class="nd">@view</span>
<span class="n">expfolder</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>       <span class="nd">@expfolder</span>
<span class="n">mod_scripting</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>   <span class="nd">@button</span><span class="p">,</span> <span class="nd">@command</span><span class="p">,</span> <span class="nd">@script</span>
<span class="n">viewrendered</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>    <span class="nd">@graphics</span><span class="o">-</span><span class="n">script</span><span class="p">,</span> <span class="nd">@image</span>
                    <span class="nd">@html</span><span class="p">,</span> <span class="nd">@movie</span><span class="p">,</span> <span class="nd">@svg</span>
</pre></div>
</div>
</section>
<section id="notable-plugins">
<h2><a class="toc-backref" href="#id12">Notable Plugins</a><a class="headerlink" href="#notable-plugins" title="Permalink to this heading">¶</a></h2>
<p>See the docstring of these plugins for more details:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">bookmarks</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>       <span class="n">Manages</span> <span class="n">URL</span><span class="s1">&#39;s used as bookmarks.</span>
<span class="n">contextmenu</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>     <span class="n">Creates</span> <span class="n">context</span> <span class="n">menus</span> <span class="k">for</span> <span class="n">headlines</span><span class="o">.</span>
<span class="n">demo</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>            <span class="n">Creates</span> <span class="n">demos</span> <span class="ow">and</span> <span class="n">slides</span><span class="o">.</span>
<span class="n">mod_scripting</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>   <span class="n">Supports</span> <span class="nd">@button</span> <span class="ow">and</span> <span class="nd">@command</span> <span class="n">nodes</span><span class="o">.</span>
<span class="n">quicksearch</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>     <span class="n">Adds</span> <span class="n">Nav</span> <span class="n">tab</span> <span class="k">for</span> <span class="n">searching</span><span class="o">.</span>
<span class="n">todo</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>            <span class="n">To</span><span class="o">-</span><span class="n">do</span> <span class="n">lists</span> <span class="ow">and</span> <span class="n">simple</span> <span class="n">project</span> <span class="n">management</span><span class="o">.</span>
<span class="n">valuespace</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>      <span class="n">Creates</span> <span class="n">an</span> <span class="n">outline</span><span class="o">-</span><span class="n">oriented</span> <span class="n">spreadsheet</span><span class="o">.</span>
<span class="n">viewrendered</span><span class="o">.</span><span class="n">py</span><span class="p">:</span>    <span class="n">Creates</span> <span class="n">a</span> <span class="n">rendering</span> <span class="n">pane</span><span class="o">.</span>
                    <span class="n">Automatically</span> <span class="n">loaded</span> <span class="n">by</span> <span class="n">Leo</span><span class="s1">&#39;s help commands.</span>
                    <span class="n">Supports</span> <span class="nd">@graphics</span><span class="o">-</span><span class="n">script</span><span class="p">,</span> <span class="nd">@image</span><span class="p">,</span> <span class="nd">@html</span><span class="p">,</span>
                    <span class="nd">@movie</span> <span class="ow">and</span> <span class="nd">@svg</span> <span class="n">nodes</span><span class="o">.</span>
<span class="n">vim</span><span class="o">.</span><span class="n">py</span> <span class="o">&amp;</span> <span class="n">xemacs</span><span class="o">.</span><span class="n">py</span>  <span class="n">Interface</span> <span class="k">with</span> <span class="n">vim</span> <span class="ow">and</span> <span class="n">xemacs</span><span class="o">.</span>
</pre></div>
</div>
</section>
<section id="external-files-file-nodes">
<h2><a class="toc-backref" href="#id13">External files (&#64;&lt;file&gt; nodes)</a><a class="headerlink" href="#external-files-file-nodes" title="Permalink to this heading">¶</a></h2>
<p>&#64;&lt;file&gt; nodes create external files:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@asis</span> <span class="o">&lt;</span><span class="n">filename</span><span class="o">&gt;</span>        <span class="n">write</span> <span class="n">only</span><span class="p">,</span> <span class="n">no</span> <span class="n">sentinels</span><span class="p">,</span> <span class="n">exact</span> <span class="n">line</span> <span class="n">endings</span>
<span class="nd">@auto</span> <span class="o">&lt;</span><span class="n">filename</span><span class="o">&gt;</span>        <span class="n">recommended</span>
<span class="nd">@clean</span> <span class="o">&lt;</span><span class="n">filename</span><span class="o">&gt;</span>       <span class="n">recommended</span>
<span class="nd">@edit</span> <span class="o">&lt;</span><span class="n">filename</span><span class="o">&gt;</span>        <span class="nd">@edit</span> <span class="n">node</span> <span class="n">contains</span> <span class="n">entire</span> <span class="n">file</span>
<span class="nd">@file</span> <span class="o">&lt;</span><span class="n">filename</span><span class="o">&gt;</span>        <span class="n">recommended</span>
<span class="nd">@nosent</span> <span class="o">&lt;</span><span class="n">filename</span><span class="o">&gt;</span>      <span class="n">write</span> <span class="n">only</span><span class="p">,</span> <span class="n">no</span> <span class="n">sentinels</span>
</pre></div>
</div>
<p>This table summarizes the differences between &#64;&lt;file&gt; nodes:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>                         Sections &amp;   File data in
@&lt;file&gt; kind  Sentinels?  @others?    .leo file?    Notes
------------  ---------- -----------  ------------  -----
@asis          no          no          yes
@auto          no          yes         no           1, 2
@auto-xx       no          yes         no           1, 2
@clean         no          yes         yes
@edit          no          no          no
@file          yes         yes         no
@nosent        no          yes         yes
</pre></div>
</div>
<p>&#64;auto nodes read files using language-specific importers.
By default, the file’s extension determines the importer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Extensions</span>                  <span class="n">Importer</span>
<span class="o">----------</span>                  <span class="o">--------</span>
<span class="o">.</span><span class="n">c</span><span class="p">,</span> <span class="o">.</span><span class="n">cc</span><span class="p">,</span> <span class="o">.</span><span class="n">c</span><span class="o">++</span><span class="p">,</span> <span class="o">.</span><span class="n">cpp</span><span class="p">,</span><span class="o">.</span><span class="n">cxx</span>    <span class="n">C</span>
<span class="o">.</span><span class="n">cs</span><span class="s1">&#39;, .c#&#39;</span>                  <span class="n">C</span> <span class="n">Sharp</span>
<span class="o">.</span><span class="n">el</span>                         <span class="n">Elisp</span>
<span class="o">.</span><span class="n">h</span><span class="p">,</span> <span class="o">.</span><span class="n">h</span><span class="o">++</span>                    <span class="n">C</span>
<span class="o">.</span><span class="n">html</span><span class="p">,</span> <span class="o">.</span><span class="n">htm</span>                 <span class="n">HTML</span>
<span class="o">.</span><span class="n">ini</span>                        <span class="n">Config</span> <span class="n">file</span>
<span class="o">.</span><span class="n">ipynb</span>                      <span class="n">Jupyter</span> <span class="n">notebook</span>
<span class="o">.</span><span class="n">java</span>                       <span class="n">Java</span>
<span class="o">.</span><span class="n">js</span>                         <span class="n">JavaScript</span>
<span class="o">.</span><span class="n">md</span>                         <span class="n">Markdown</span>
<span class="o">.</span><span class="n">org</span>                        <span class="n">Org</span> <span class="n">Mode</span>
<span class="o">.</span><span class="n">otl</span>                        <span class="n">Vim</span> <span class="n">outline</span>
<span class="o">.</span><span class="n">pas</span>                        <span class="n">Pascal</span>
<span class="o">.</span><span class="n">php</span>                        <span class="n">PHP</span>
<span class="o">.</span><span class="n">py</span><span class="p">,</span> <span class="o">.</span><span class="n">pyi</span><span class="p">,</span> <span class="o">.</span><span class="n">pyw</span>             <span class="n">Python</span>
<span class="o">.</span><span class="n">rest</span><span class="p">,</span> <span class="o">.</span><span class="n">rst</span>                 <span class="n">reStructuredText</span>
<span class="o">.</span><span class="n">ts</span>                         <span class="n">TypeScript</span>
<span class="o">.</span><span class="n">xml</span>                        <span class="n">XML</span>
</pre></div>
</div>
<p>You can also specify importers <em>explicitly</em> as follows:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@auto</span><span class="o">-</span><span class="n">xxx</span>           <span class="n">Importer</span>
<span class="o">---------</span>           <span class="o">--------</span>
<span class="nd">@auto</span><span class="o">-</span><span class="n">ctext</span>         <span class="n">ctext</span>
<span class="nd">@auto</span><span class="o">-</span><span class="n">markdown</span>      <span class="n">markdown</span>
<span class="nd">@auto</span><span class="o">-</span><span class="n">md</span>            <span class="n">markdown</span>
<span class="nd">@auto</span><span class="o">-</span><span class="n">org</span>           <span class="n">org</span><span class="o">-</span><span class="n">mode</span>
<span class="nd">@auto</span><span class="o">-</span><span class="n">org</span><span class="o">-</span><span class="n">mode</span>      <span class="n">org</span><span class="o">-</span><span class="n">mode</span>
<span class="nd">@auto</span><span class="o">-</span><span class="n">otl</span>           <span class="n">vimoutline</span>
<span class="nd">@auto</span><span class="o">-</span><span class="n">vim</span><span class="o">-</span><span class="n">outline</span>   <span class="n">vimoutline</span>
<span class="nd">@auto</span><span class="o">-</span><span class="n">rst</span>           <span class="n">reStructuredText</span>
</pre></div>
</div>
<p><strong>Important</strong>: The importers/exporters for markdown, org-mode, reStructuredText and vimoutline files automatically generate section headings corresponding to Leo’s outline level. Body text of the top-level &#64;auto node is ignored.</p>
<p>See the <a class="reference external" href="directives.html">Directives reference</a> for full details.</p>
</section>
<section id="sections">
<h2><a class="toc-backref" href="#id14">Sections</a><a class="headerlink" href="#sections" title="Permalink to this heading">¶</a></h2>
<p><strong>Section names</strong> have the form:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;&lt;</span> <span class="nb">any</span> <span class="n">text</span><span class="p">,</span> <span class="k">except</span> <span class="n">double</span> <span class="n">closing</span> <span class="n">angle</span> <span class="n">brackets</span> <span class="o">&gt;&gt;</span>
</pre></div>
</div>
<p><strong>Section-definition nodes</strong> have headlines starting with a section name.</p>
<p>Leo performs <strong>expansions</strong> for all &#64;&lt;file&gt; nodes except &#64;asis.</p>
<p>Expansion of &#64;all:</p>
<ul class="simple">
<li><p>Leo replaces &#64;all by the <em>unexpanded</em> body text of <em>all</em> nodes.</p></li>
</ul>
<p>Expansion of section names and &#64;others:</p>
<ul class="simple">
<li><p>Leo replaces section names in body text by the <em>expanded</em>
text of the corresponding section definition node.</p></li>
<li><p>Leo replaces &#64;others with the <em>expanded</em> text of all nodes
that <em>aren’t</em> section-definition nodes.</p></li>
</ul>
</section>
<section id="scripting">
<h2><a class="toc-backref" href="#id15">Scripting</a><a class="headerlink" href="#scripting" title="Permalink to this heading">¶</a></h2>
<p>This section lists the ivars (instance variables), properties, functions and methods most commonly used in Leo scripts.</p>
<p><strong>Very important</strong>: use Alt-1 (toggle-autocompleter) and Alt-2 (toggle-calltips) to recreate these lists as you type.</p>
<section id="pre-defined-symbols">
<h3><a class="toc-backref" href="#id16">Pre-defined symbols</a><a class="headerlink" href="#pre-defined-symbols" title="Permalink to this heading">¶</a></h3>
<p>execute-script predefines:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">c</span><span class="p">:</span> <span class="n">The</span> <span class="n">commander</span> <span class="n">of</span> <span class="n">the</span> <span class="n">present</span> <span class="n">outline</span><span class="o">.</span>
<span class="n">g</span><span class="p">:</span> <span class="n">The</span> <span class="n">leo</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">leoGlobals</span> <span class="n">module</span><span class="o">.</span>
<span class="n">p</span><span class="p">:</span> <span class="n">The</span> <span class="n">presently</span> <span class="n">selected</span> <span class="n">position</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">p</span><span class="o">.</span>
</pre></div>
</div>
</section>
<section id="leoapp-class">
<h3><a class="toc-backref" href="#id17">LeoApp class</a><a class="headerlink" href="#leoapp-class" title="Permalink to this heading">¶</a></h3>
<p><strong>Ivars</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">g</span><span class="o">.</span><span class="n">app</span>                   <span class="n">A</span> <span class="n">LeoApp</span> <span class="n">instance</span><span class="o">.</span>
<span class="n">g</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">gui</span>               <span class="n">A</span> <span class="n">LeoGui</span> <span class="n">instance</span><span class="o">.</span>
<span class="n">g</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">pluginsController</span> <span class="n">A</span> <span class="n">LeoPluginsController</span> <span class="n">instance</span><span class="o">.</span>
<span class="n">g</span><span class="o">.</span><span class="n">app</span><span class="o">.*</span>                 <span class="n">Leo</span><span class="s1">&#39;s global variables.</span>
</pre></div>
</div>
</section>
<section id="commands-class">
<h3><a class="toc-backref" href="#id18">Commands class</a><a class="headerlink" href="#commands-class" title="Permalink to this heading">¶</a></h3>
<p><strong>Ivars</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">c</span><span class="o">.</span><span class="n">config</span>                <span class="n">c</span><span class="s1">&#39;s configuration object</span>
<span class="n">c</span><span class="o">.</span><span class="n">frame</span>                 <span class="n">c</span><span class="s1">&#39;s outer frame, a leoFrame instance.</span>
<span class="n">c</span><span class="o">.</span><span class="n">undoer</span>                <span class="n">c</span><span class="s1">&#39;s undo handler.</span>
<span class="n">c</span><span class="o">.</span><span class="n">user_dict</span>             <span class="n">A</span> <span class="n">temporary</span> <span class="nb">dict</span> <span class="k">for</span> <span class="n">use</span> <span class="n">of</span> <span class="n">scripts</span> <span class="ow">and</span> <span class="n">plugins</span><span class="o">.</span>
</pre></div>
</div>
<p><strong>SubCommanders</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># In leo/core...</span>
<span class="n">c</span><span class="o">.</span><span class="n">atFileCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">chapterController</span>
<span class="n">c</span><span class="o">.</span><span class="n">fileCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">findCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">importCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">keyHandler</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">k</span>
<span class="n">c</span><span class="o">.</span><span class="n">persistenceController</span>
<span class="n">c</span><span class="o">.</span><span class="n">printingController</span>
<span class="n">c</span><span class="o">.</span><span class="n">rstCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">shadowController</span>
<span class="n">c</span><span class="o">.</span><span class="n">tangleCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">testManager</span>
<span class="n">c</span><span class="o">.</span><span class="n">vimCommands</span>

<span class="c1"># In leo/commands...</span>
<span class="n">c</span><span class="o">.</span><span class="n">abbrevCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">controlCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">convertCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">debugCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">editCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">editFileCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">gotoCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">helpCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">keyHandlerCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">killBufferCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">rectangleCommands</span>
<span class="n">c</span><span class="o">.</span><span class="n">spellCommands</span>
</pre></div>
</div>
<p><strong>Generators</strong> (New in Leo 5.5: All generators yield distinct positions):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">c</span><span class="o">.</span><span class="n">all_positions</span><span class="p">()</span>
<span class="n">c</span><span class="o">.</span><span class="n">all_unique_positions</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Most useful methods</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">c</span><span class="o">.</span><span class="n">isChanged</span><span class="p">()</span>
<span class="n">c</span><span class="o">.</span><span class="n">deletePositionsInList</span><span class="p">(</span><span class="n">aList</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
                        <span class="c1"># safely deletes all the positions in aList.</span>
<span class="n">c</span><span class="o">.</span><span class="n">positionExists</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="n">c</span><span class="o">.</span><span class="n">redraw</span><span class="p">(</span><span class="n">p</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>        <span class="c1"># Redraw the screen. Select p if given.</span>
<span class="n">c</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>                <span class="c1"># Save the present outline.</span>
<span class="n">c</span><span class="o">.</span><span class="n">selectPosition</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Official ivars</strong> of any leoFrame f:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>f.c                     is the frame’s commander.
f.body                  is a leoBody instance.
f.body.bodyCtl          is a leoQTextEditWidget instance.
f.body.bodyCtrl.widget  is a LeoQTextBrowser(QTextBrowser) instance.
f.log                   is a leoLog instance.
f.tree                  is a leoQtTree instance.
f.tree.treeWidget       is a LeoQTreeWidget (a QTreeWidget) instance.
</pre></div>
</div>
<p>Use autocompletion to explore these objects!</p>
</section>
<section id="undoing-commands">
<h3><a class="toc-backref" href="#id19">Undoing commands</a><a class="headerlink" href="#undoing-commands" title="Permalink to this heading">¶</a></h3>
<p>If you want to make a command undoable, you must create “before” and “after” snapshots of the parts of the outline that may change. Here are some examples.  Leo’s source code contains many other examples.</p>
<section id="undoably-changing-body-text">
<h4><a class="toc-backref" href="#id20">Undoably changing body text</a><a class="headerlink" href="#undoably-changing-body-text" title="Permalink to this heading">¶</a></h4>
<p>To undo a single change to body text:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">command</span> <span class="o">=</span> <span class="s1">&#39;my-command-name&#39;</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">undoer</span><span class="o">.</span><span class="n">beforeChangeNodeContents</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">oldYScroll</span><span class="o">=</span><span class="n">ypos</span><span class="p">)</span>
<span class="c1"># Change p&#39;s body text.</span>
<span class="n">c</span><span class="o">.</span><span class="n">undoer</span><span class="o">.</span><span class="n">afterChangeNodeContents</span><span class="p">(</span><span class="n">p</span><span class="p">,</span>
    <span class="n">command</span><span class="o">=</span><span class="n">command</span><span class="p">,</span> <span class="n">bunch</span><span class="o">=</span><span class="n">b</span><span class="p">,</span> <span class="n">dirtyVnodeList</span><span class="o">=</span><span class="p">[])</span>
</pre></div>
</div>
</section>
<section id="undoably-changing-multiple-nodes">
<h4><a class="toc-backref" href="#id21">Undoably changing multiple nodes</a><a class="headerlink" href="#undoably-changing-multiple-nodes" title="Permalink to this heading">¶</a></h4>
<p>If your command changes multiple nodes, the pattern is:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">u</span><span class="p">,</span> <span class="n">undoType</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">undoer</span><span class="p">,</span> <span class="s1">&#39;command-name&#39;</span>
<span class="n">u</span><span class="o">.</span><span class="n">beforeChangeGroup</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">undoType</span><span class="p">)</span>
<span class="n">dirtyVnodeList</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">changed</span> <span class="o">=</span> <span class="kc">False</span>
<span class="c1"># For each change, do something like the following:</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">to_be_changed_nodes</span><span class="p">:</span>
    <span class="c1"># Change p.</span>
    <span class="n">dirtyVnodeList</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">v</span><span class="p">)</span>
    <span class="n">u</span><span class="o">.</span><span class="n">afterChangeNodeContents</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">undoType</span><span class="p">,</span> <span class="n">bunch</span><span class="p">)</span>
    <span class="n">changed</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">if</span> <span class="n">changed</span><span class="p">:</span>
    <span class="n">u</span><span class="o">.</span><span class="n">afterChangeGroup</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">undoType</span><span class="p">,</span>
        <span class="n">reportFlag</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
        <span class="n">dirtyVnodeList</span><span class="o">=</span><span class="n">dirtyVnodeList</span><span class="p">)</span>
</pre></div>
</div>
</section>
</section>
<section id="vnode-class">
<h3><a class="toc-backref" href="#id22">VNode class</a><a class="headerlink" href="#vnode-class" title="Permalink to this heading">¶</a></h3>
<p><strong>Ivars</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">v</span><span class="o">.</span><span class="n">b</span><span class="p">:</span>    <span class="n">v</span><span class="s1">&#39;s body text.</span>
<span class="n">v</span><span class="o">.</span><span class="n">gnx</span>   <span class="n">v</span><span class="s1">&#39;s gnx.</span>
<span class="n">v</span><span class="o">.</span><span class="n">h</span><span class="p">:</span>    <span class="n">v</span><span class="s1">&#39;s headline text.</span>
<span class="n">v</span><span class="o">.</span><span class="n">u</span><span class="p">:</span>    <span class="n">v</span><span class="o">.</span><span class="n">unknownAttributes</span><span class="p">,</span> <span class="n">a</span> <span class="n">persistent</span> <span class="n">Python</span> <span class="n">dictionary</span><span class="o">.</span>
</pre></div>
</div>
<p>v.u (uA’s or unknownAttributes or userAttributes) allow plugins or scripts
to associate persistent data with vnodes. For details see the section about
<a class="reference external" href="customizing.html#adding-extensible-attributes-to-nodes-and-leo-files">userAttributes</a> in the <a class="reference external" href="customizing.html">Customizing Leo</a> chapter.</p>
<p><em>Important</em>: Generally speaking, vnode properties are fast, while the
corresponding position properties are much slower. Nevertheless, scripts
should usually use <em>position</em> properties rather than <em>vnode</em> properties
because the position properties handle recoloring and other details.
Scripts should use <em>vnode</em> properties only when making batch changes to
vnodes.</p>
</section>
<section id="position-class">
<h3><a class="toc-backref" href="#id23">Position class</a><a class="headerlink" href="#position-class" title="Permalink to this heading">¶</a></h3>
<p><strong>Properties</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">p</span><span class="o">.</span><span class="n">b</span><span class="p">:</span> <span class="n">same</span> <span class="k">as</span> <span class="n">p</span><span class="o">.</span><span class="n">v</span><span class="o">.</span><span class="n">b</span><span class="o">.</span>  <span class="o">*</span><span class="ne">Warning</span><span class="o">*</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="n">s</span> <span class="ow">is</span> <span class="n">expensive</span><span class="o">.</span>
<span class="n">p</span><span class="o">.</span><span class="n">h</span><span class="p">:</span> <span class="n">same</span> <span class="k">as</span> <span class="n">p</span><span class="o">.</span><span class="n">v</span><span class="o">.</span><span class="n">h</span><span class="o">.</span>  <span class="o">*</span><span class="ne">Warning</span><span class="o">*</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">h</span> <span class="o">=</span> <span class="n">s</span> <span class="ow">is</span> <span class="n">expensive</span><span class="o">.</span>
<span class="n">p</span><span class="o">.</span><span class="n">u</span><span class="p">:</span> <span class="n">same</span> <span class="k">as</span> <span class="n">p</span><span class="o">.</span><span class="n">v</span><span class="o">.</span><span class="n">u</span><span class="o">.</span>
</pre></div>
</div>
<p><strong>Generators</strong> (New in Leo 5.5: All generators yield distinct positions):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">p</span><span class="o">.</span><span class="n">children</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">parents</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">self_and_parents</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">self_and_siblings</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">following_siblings</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">subtree</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">self_and_subtree</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Getters</strong> These return <em>new positions</em>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">p</span><span class="o">.</span><span class="n">back</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">children</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">firstChild</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">hasBack</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">hasChildren</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">hasNext</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">hasParent</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">hasThreadBack</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">hasThreadNext</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">isAncestorOf</span><span class="p">(</span><span class="n">p2</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">isAnyAtFileNode</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">isAt</span><span class="o">...</span><span class="n">Node</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">isCloned</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">isDirty</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">isExpanded</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">isMarked</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">isRoot</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">isVisible</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">lastChild</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">level</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">nodeAfterTree</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">nthChild</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">numberOfChildren</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">parent</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">parents</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">threadBack</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">threadNext</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">visBack</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">visNext</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Setters</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">p</span><span class="o">.</span><span class="n">setDirty</span><span class="p">()</span>  <span class="o">*</span><span class="ne">Warning</span><span class="o">*</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">setDirty</span><span class="p">()</span> <span class="ow">is</span> <span class="n">expensive</span><span class="o">.</span>
<span class="n">p</span><span class="o">.</span><span class="n">setMarked</span><span class="p">()</span>
</pre></div>
</div>
<p><strong>Operations on nodes</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">p</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">contract</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">doDelete</span><span class="p">(</span><span class="n">new_position</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">expand</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">insertAfter</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">insertAsNthChild</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">insertBefore</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveAfter</span><span class="p">(</span><span class="n">p2</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToFirstChildOf</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span><span class="n">n</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToLastChildOf</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span><span class="n">n</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToNthChildOf</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span><span class="n">n</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToRoot</span><span class="p">(</span><span class="n">oldRoot</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
    <span class="c1"># oldRoot **must** be the old root position if it exists.</span>
</pre></div>
</div>
<p><strong>Moving positions</strong></p>
<p>The following move positions <em>themselves</em>: they change the node to which a
position refers. They do <em>not</em> change outline structure in any way! Use
these when generators are not flexible enough:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">p</span><span class="o">.</span><span class="n">moveToBack</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToFirstChild</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToLastChild</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToLastNode</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToNext</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToNodeAfterTree</span><span class="p">(</span><span class="n">p2</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToNthChild</span><span class="p">(</span><span class="n">n</span><span class="p">))</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToParent</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToThreadBack</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToThreadNext</span><span class="p">()</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToVisBack</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
<span class="n">p</span><span class="o">.</span><span class="n">moveToVisNext</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="leo-core-leoglobals-module">
<h3><a class="toc-backref" href="#id24">leo.core.leoGlobals module</a><a class="headerlink" href="#leo-core-leoglobals-module" title="Permalink to this heading">¶</a></h3>
<p>For full details, see &#64;file leoGlobals.py in LeoPyRef.leo.</p>
<p><strong>g vars</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">g</span><span class="o">.</span><span class="n">app</span>
<span class="n">g</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">gui</span>
<span class="n">g</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">windowlist</span>
<span class="n">g</span><span class="o">.</span><span class="n">unitTesting</span>
<span class="n">g</span><span class="o">.</span><span class="n">user_dict</span>  <span class="c1"># a temporary dict for use of scripts and plugins.</span>
</pre></div>
</div>
<p><strong>g decorator</strong>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@g</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="n">command</span><span class="o">-</span><span class="n">name</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>g functions</strong> (the most interesting: there are many more in leoGlobals.py):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">g</span><span class="o">.</span><span class="n">angleBrackets</span><span class="p">()</span>
<span class="n">g</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">commanders</span><span class="p">()</span>
<span class="n">g</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">gui</span><span class="o">.</span><span class="n">guiName</span><span class="p">()</span>
<span class="n">g</span><span class="o">.</span><span class="n">es</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span><span class="o">**</span><span class="n">keys</span><span class="p">)</span>
<span class="n">g</span><span class="o">.</span><span class="n">es_print</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span><span class="o">**</span><span class="n">keys</span><span class="p">)</span>
<span class="n">g</span><span class="o">.</span><span class="n">es_exception</span><span class="p">()</span>
<span class="n">g</span><span class="o">.</span><span class="n">getScript</span><span class="p">(</span><span class="n">c</span><span class="p">,</span><span class="n">p</span><span class="p">,</span>
    <span class="n">useSelectedText</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
    <span class="n">forcePythonSentinels</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
    <span class="n">useSentinels</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">g</span><span class="o">.</span><span class="n">openWithFileName</span><span class="p">(</span><span class="n">fileName</span><span class="p">,</span><span class="n">old_c</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="n">gui</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
<span class="n">g</span><span class="o">.</span><span class="n">os_path_</span><span class="o">...</span> <span class="c1"># Wrappers for os.path methods.</span>
<span class="n">g</span><span class="o">.</span><span class="n">pdb</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="n">g</span><span class="o">.</span><span class="n">toEncodedString</span><span class="p">(</span><span class="n">s</span><span class="p">,</span><span class="n">encoding</span><span class="o">=</span><span class="s1">&#39;utf-8&#39;</span><span class="p">,</span><span class="n">reportErrors</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">g</span><span class="o">.</span><span class="n">toUnicode</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s1">&#39;utf-8&#39;</span><span class="p">,</span><span class="n">reportErrors</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">g</span><span class="o">.</span><span class="n">trace</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span><span class="o">**</span><span class="n">keys</span><span class="p">)</span>
<span class="n">g</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span><span class="o">**</span><span class="n">keys</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="test-driven-development">
<h3><a class="toc-backref" href="#id25">Test driven development</a><a class="headerlink" href="#test-driven-development" title="Permalink to this heading">¶</a></h3>
<ul class="simple">
<li><p>Use <a class="reference external" href="https://docs.python.org/3/library/imp.html">imp.reload</a> to reload all changed modules.</p></li>
<li><p>Make sure to <em>instantiate</em> any changed objects.</p></li>
<li><p>See <a class="reference external" href="unitTesting.html#test-driven-development-in-leo">this section</a> for full details.</p></li>
</ul>
</section>
<section id="performance-gotchas">
<h3><a class="toc-backref" href="#id26">Performance gotchas</a><a class="headerlink" href="#performance-gotchas" title="Permalink to this heading">¶</a></h3>
<p><strong>Warning</strong>: The p.b and p.h setters and p.setDirty() are <em>very</em> expensive:</p>
<ul class="simple">
<li><p>p.b = s calls c.setBodyString(p, s) which will recolor body text and update the node’s icon.</p></li>
<li><p>p.h = s calls c.setHeadString(p, s) which calls p.setDirty().</p></li>
<li><p>p.setDirty() changes the icons of all ancestor &#64;file nodes.</p></li>
</ul>
<p>In contrast, the corresponding p.v.b and p.v.b setters and p.v.setDirty() are extremely fast.</p>
<p>Usually, code <em>should</em> use the p.b and p.h setters and p.setDirty(), despite their cost, because they update Leo’s outline pane properly. Calling c.redraw() is <em>not</em> enough.</p>
<p>These performance gotchas become important for repetitive commands, like cff, replace-all and recursive import. In such situations, code should use p.v.b and p.v.h setters instead of p.b and p.h setters.</p>
</section>
<section id="prompting-for-command-arguments">
<h3><a class="toc-backref" href="#id27">Prompting for command arguments</a><a class="headerlink" href="#prompting-for-command-arguments" title="Permalink to this heading">¶</a></h3>
<section id="example-1-prompt-for-one-arg">
<h4><a class="toc-backref" href="#id28">Example 1: Prompt for one arg</a><a class="headerlink" href="#example-1-prompt-for-one-arg" title="Permalink to this heading">¶</a></h4>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@g</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="s1">&#39;i1&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">i1_command</span><span class="p">(</span><span class="n">event</span><span class="p">):</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="p">:</span> <span class="k">return</span>

    <span class="k">def</span> <span class="nf">callback</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="n">g</span><span class="o">.</span><span class="n">trace</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
        <span class="n">c</span><span class="o">.</span><span class="n">bodyWantsFocus</span><span class="p">()</span>

    <span class="n">c</span><span class="o">.</span><span class="n">interactive</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span> <span class="n">prompts</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;Prompt: &#39;</span><span class="p">])</span>
</pre></div>
</div>
</section>
<section id="example-2-prompt-for-2-args">
<h4><a class="toc-backref" href="#id29">Example 2: Prompt for 2 args</a><a class="headerlink" href="#example-2-prompt-for-2-args" title="Permalink to this heading">¶</a></h4>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@g</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="s1">&#39;i2&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">i2_command</span><span class="p">(</span><span class="n">event</span><span class="p">):</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="p">:</span> <span class="k">return</span>

    <span class="k">def</span> <span class="nf">callback</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="n">g</span><span class="o">.</span><span class="n">trace</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
        <span class="n">c</span><span class="o">.</span><span class="n">bodyWantsFocus</span><span class="p">()</span>

    <span class="n">c</span><span class="o">.</span><span class="n">interactive</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span>
        <span class="n">prompts</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;Find: &#39;</span><span class="p">,</span> <span class="s1">&#39; Replace: &#39;</span><span class="p">])</span>
</pre></div>
</div>
</section>
<section id="example-3-prompt-for-3-args">
<h4><a class="toc-backref" href="#id30">Example 3: Prompt for 3 args</a><a class="headerlink" href="#example-3-prompt-for-3-args" title="Permalink to this heading">¶</a></h4>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@g</span><span class="o">.</span><span class="n">command</span><span class="p">(</span><span class="s1">&#39;i3&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">i3_command</span><span class="p">(</span><span class="n">event</span><span class="p">):</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="p">:</span> <span class="k">return</span>

    <span class="k">def</span> <span class="nf">callback</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
        <span class="n">g</span><span class="o">.</span><span class="n">trace</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
        <span class="n">c</span><span class="o">.</span><span class="n">bodyWantsFocus</span><span class="p">()</span>

    <span class="n">c</span><span class="o">.</span><span class="n">interactive</span><span class="p">(</span><span class="n">callback</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span>
        <span class="n">prompts</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;One: &#39;</span><span class="p">,</span> <span class="s1">&#39; Two: &#39;</span><span class="p">,</span> <span class="s1">&#39; Three: &#39;</span><span class="p">])</span>
</pre></div>
</div>
</section>
</section>
<section id="naming-conventions-in-leo-s-core">
<h3><a class="toc-backref" href="#id31">Naming conventions in Leo’s core</a><a class="headerlink" href="#naming-conventions-in-leo-s-core" title="Permalink to this heading">¶</a></h3>
<p>LeoPyRef.leo contains all of Leo’s core source code.</p>
<p>Leo’s code uses the following conventions throughout:</p>
<p>c:  a commander.
ch: a character.
d:  a dialog or a dict.
f:  an open file.
fn: a file name.
g:  the leoGlobals module.
i, j, k: indices into a string.
p:  a Position.
s:  a string.
t:  a text widget.
u:  an undoer.
w:  a gui widget.
v:  a Vnode
z:  a local temp.</p>
<p>In more limited contexts, the following conventions apply:</p>
<p>si:     a g.ShortcutInfo object.
ks:     a g.KeyStroke object
stroke: a KeyStroke object.</p>
<p>btw:    leoFrame.BaseTextWrapper
stw:    leoFrame.StringTextWrapper</p>
<p>bqtw:   qt_text.BaseQTextWrapper
lqtb:   qt_text.LeoQTextBrowser
qhlw:   qt_text.QHeadlineWrapper
qmbw:   qt_text.QMinibufferWrapper
qlew:   qt_text.QLineEditWrapper
qsciw:  qt_text.QScintiallaWrapper
qtew:   qt_text.QTextEditWrapper</p>
<p>Names defined in Leo’s core are unlikely to change, especially names used outside their defining module. This includes virtually everything in leoGlobals.py, and many names in leoCommands.py and other files.</p>
<section id="official-ivars">
<h4><a class="toc-backref" href="#id32">Official ivars</a><a class="headerlink" href="#official-ivars" title="Permalink to this heading">¶</a></h4>
<p>The following ‘official’ ivars (instance vars) will always exist:</p>
<p>c.frame                 The frame containing the log,body,tree, etc.
c.frame.body            The body pane.
c.frame.body.widget     The gui widget for the body pane.
c.frame.body.wrapper    The high level interface for the body widget.
c.frame.iconBar         The icon bar.
c.frame.log             The log pane.
c.frame.log.widget      The gui widget for the log pane.
c.frame.log.wrapper     The high-level interface for the log pane.
c.frame.tree            The tree pane.</p>
<p>The following were official ivars that no longer exist:</p>
<p>c.frame.body.bodyCtrl   Use c.frame.body.wrapper instead.
c.frame.log.logCtrl     Use c.frame.log.wrapper instead.</p>
</section>
</section>
<section id="widgets-and-wrappers">
<h3><a class="toc-backref" href="#id33">Widgets and wrappers</a><a class="headerlink" href="#widgets-and-wrappers" title="Permalink to this heading">¶</a></h3>
<p>A <strong>widget</strong> is an actual Qt widget. Leo’s core seldom accesses widgets directly.  Instead, a  <strong>wrapper class</strong> defines a standard api that hides the details of the underlying gui <strong>text</strong> widgets.</p>
<p>Leo’s core uses the wrapper api almost exclusively. That is, Leo’s core code treats wrappers <em>as if</em> they were only text widgets there are!</p>
<p>A back door exists for special cases. All wrapper classes define an official <code class="docutils literal notranslate"><span class="pre">widget</span></code> ivar, so core or plugin code can gain access to the real Qt widget using wrapper.widget. Searching for wrapper.widget will find all gui-dependent snippets of code in Leo’s core.</p>
</section>
</section>
<section id="command-line-options">
<h2><a class="toc-backref" href="#id34">Command-line options</a><a class="headerlink" href="#command-line-options" title="Permalink to this heading">¶</a></h2>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Usage</span><span class="p">:</span> <span class="n">launchLeo</span><span class="o">.</span><span class="n">py</span> <span class="p">[</span><span class="n">options</span><span class="p">]</span> <span class="n">file1</span><span class="p">,</span> <span class="n">file2</span><span class="p">,</span> <span class="o">...</span>

<span class="n">Options</span><span class="p">:</span>
  <span class="o">-</span><span class="n">h</span><span class="p">,</span> <span class="o">--</span><span class="n">help</span>            <span class="n">show</span> <span class="n">this</span> <span class="n">help</span> <span class="n">message</span> <span class="ow">and</span> <span class="n">exit</span>
  <span class="o">--</span><span class="n">debug</span>               <span class="n">enable</span> <span class="n">debug</span> <span class="n">mode</span>
  <span class="o">--</span><span class="n">diff</span>                <span class="n">use</span> <span class="n">Leo</span> <span class="k">as</span> <span class="n">an</span> <span class="n">external</span> <span class="n">git</span> <span class="n">diff</span>
  <span class="o">--</span><span class="n">fullscreen</span>          <span class="n">start</span> <span class="n">fullscreen</span>
  <span class="o">--</span><span class="n">ipython</span>             <span class="n">enable</span> <span class="n">ipython</span> <span class="n">support</span>
  <span class="o">--</span><span class="n">fail</span><span class="o">-</span><span class="n">fast</span>           <span class="n">stop</span> <span class="n">unit</span> <span class="n">tests</span> <span class="n">after</span> <span class="n">the</span> <span class="n">first</span> <span class="n">failure</span>
  <span class="o">--</span><span class="n">gui</span><span class="o">=</span><span class="n">GUI</span>             <span class="n">gui</span> <span class="n">to</span> <span class="n">use</span> <span class="p">(</span><span class="n">qt</span><span class="o">/</span><span class="n">qttabs</span><span class="p">)</span>
  <span class="o">--</span><span class="n">load</span><span class="o">-</span><span class="nb">type</span><span class="o">=</span><span class="n">LOAD_TYPE</span>
                        <span class="o">@&lt;</span><span class="n">file</span><span class="o">&gt;</span> <span class="nb">type</span> <span class="k">for</span> <span class="n">loading</span> <span class="n">non</span><span class="o">-</span><span class="n">outlines</span> <span class="kn">from</span> <span class="nn">command</span>
                        <span class="n">line</span>
  <span class="o">--</span><span class="n">maximized</span>           <span class="n">start</span> <span class="n">maximized</span>
  <span class="o">--</span><span class="n">minimized</span>           <span class="n">start</span> <span class="n">minimized</span>
  <span class="o">--</span><span class="n">no</span><span class="o">-</span><span class="n">cache</span>            <span class="n">disable</span> <span class="n">reading</span> <span class="n">of</span> <span class="n">cached</span> <span class="n">files</span>
  <span class="o">--</span><span class="n">no</span><span class="o">-</span><span class="n">plugins</span>          <span class="n">disable</span> <span class="nb">all</span> <span class="n">plugins</span>
  <span class="o">--</span><span class="n">no</span><span class="o">-</span><span class="n">splash</span>           <span class="n">disable</span> <span class="n">the</span> <span class="n">splash</span> <span class="n">screen</span>
  <span class="o">--</span><span class="n">screen</span><span class="o">-</span><span class="n">shot</span><span class="o">=</span><span class="n">SCREENSHOT_FN</span>
                        <span class="n">take</span> <span class="n">a</span> <span class="n">screen</span> <span class="n">shot</span> <span class="ow">and</span> <span class="n">then</span> <span class="n">exit</span>
  <span class="o">--</span><span class="n">script</span><span class="o">=</span><span class="n">SCRIPT</span>       <span class="n">execute</span> <span class="n">a</span> <span class="n">script</span> <span class="ow">and</span> <span class="n">then</span> <span class="n">exit</span>
  <span class="o">--</span><span class="n">script</span><span class="o">-</span><span class="n">window</span><span class="o">=</span><span class="n">SCRIPT_WINDOW</span>
                        <span class="nb">open</span> <span class="n">a</span> <span class="n">window</span> <span class="k">for</span> <span class="n">scripts</span>
  <span class="o">--</span><span class="n">select</span><span class="o">=</span><span class="n">SELECT</span>       <span class="n">headline</span> <span class="ow">or</span> <span class="n">gnx</span> <span class="n">of</span> <span class="n">node</span> <span class="n">to</span> <span class="n">select</span>
  <span class="o">--</span><span class="n">silent</span>              <span class="n">disable</span> <span class="nb">all</span> <span class="n">log</span> <span class="n">messages</span>
  <span class="o">--</span><span class="n">trace</span><span class="o">-</span><span class="n">plugins</span>       <span class="n">trace</span> <span class="n">imports</span> <span class="n">of</span> <span class="n">plugins</span>
  <span class="o">-</span><span class="n">v</span><span class="p">,</span> <span class="o">--</span><span class="n">version</span>         <span class="nb">print</span> <span class="n">version</span> <span class="n">number</span> <span class="ow">and</span> <span class="n">exit</span>
  <span class="o">--</span><span class="n">window</span><span class="o">-</span><span class="n">size</span><span class="o">=</span><span class="n">WINDOW_SIZE</span>
                        <span class="n">initial</span> <span class="n">window</span> <span class="n">size</span> <span class="p">(</span><span class="n">height</span> <span class="n">x</span> <span class="n">width</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="learning-to-be-a-leo-developer">
<h2><a class="toc-backref" href="#id35">Learning to be a Leo developer</a><a class="headerlink" href="#learning-to-be-a-leo-developer" title="Permalink to this heading">¶</a></h2>
<section id="code-academy">
<h3><a class="toc-backref" href="#id36">Code academy</a><a class="headerlink" href="#code-academy" title="Permalink to this heading">¶</a></h3>
<p>Leo’s Code Academy posts discuss how to do useful things in Leo. The following are distilled from online discussions about Leo’s scripting.</p>
<section id="ca-ua-s">
<h4><a class="toc-backref" href="#id37">CA: uA’s</a><a class="headerlink" href="#ca-ua-s" title="Permalink to this heading">¶</a></h4>
<p>uA’s (user Attributes) associate arbitrary data with any vnode. uA’s are dictionaries of dictionaries–an <strong>outer dictionary</strong> and zero or more <strong>inner dictionaries</strong>. The outer dictionary associates plugin names (or Leo’s core) with inner dictionaries. The inner dictionaries carry the actual data.</p>
<p>The v.u or p.v properties get and set uA’s. You can think of p.u as a synonym for p.v.unknownAttributes on both sides of an assignment. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plugin_name</span> <span class="o">=</span> <span class="s1">&#39;test_plugin&#39;</span>
<span class="n">d</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">u</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">plugin_name</span><span class="p">,{})</span>
<span class="n">d</span> <span class="p">[</span><span class="s1">&#39;n&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">8</span>
<span class="n">p</span><span class="o">.</span><span class="n">u</span> <span class="p">[</span><span class="n">plugin_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">d</span>
</pre></div>
</div>
<p>p.u is the outer dictionary. p.u.get.(plugin_name, {}) is the inner dictionary. The last line is all that is needed to update the outer dictionary!</p>
<p>It is easy to search for particular uA’s. The following script prints all the keys in the outer-level uA dictionaries:</p>
<blockquote>
<div><dl class="simple">
<dt>for p in c.all_unique_positions():</dt><dd><dl class="simple">
<dt>if p.u:</dt><dd><p>print(p.h, sorted(p.u.keys()))</p>
</dd>
</dl>
</dd>
</dl>
</div></blockquote>
<p>This is a typical usage of Leo’s generators.  Generators visit each position (or node) quickly. Even if you aren’t going to program much, you should be aware of how easy it is to get and set the data in each node. In fact, now would be a great time to read Leo’s Scripting Tutorial again :-) This will allow you to “dream bigger” with Leo.</p>
<p>The following script creates a list of all positions having an icon, that is, an outer uA dict with a ‘icon’ key.</p>
<blockquote>
<div><p>aList = [p.copy() for p in c.all_unique_positions() if ‘icon’ in p.u]
print(’n’.join([p.h for p in aList]))</p>
</div></blockquote>
<p><em>Important</em>: If you don’t understand these lines, please study Python’s list comprehensions.  They are incredibly useful. ‘n’.join(aList) is a great idiom to know.  str.join is one of python’s most useful string methods. It converts between lists and strings.</p>
</section>
<section id="ca-icons">
<h4><a class="toc-backref" href="#id38">CA: icons</a><a class="headerlink" href="#ca-icons" title="Permalink to this heading">¶</a></h4>
<p>This script inserts three icons in the current outline node. Running
the script again will insert three more:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">table</span> <span class="o">=</span> <span class="p">(</span>
    <span class="s1">&#39;edittrash.png&#39;</span><span class="p">,</span>
    <span class="s1">&#39;connect_no.png&#39;</span><span class="p">,</span>
    <span class="s1">&#39;error.png&#39;</span><span class="p">,</span>
<span class="p">)</span>
<span class="k">for</span> <span class="n">icon</span> <span class="ow">in</span> <span class="n">table</span><span class="p">:</span>
    <span class="n">fn</span> <span class="o">=</span> <span class="n">g</span><span class="o">.</span><span class="n">os_path_finalize_join</span><span class="p">(</span><span class="n">g</span><span class="o">.</span><span class="n">app</span><span class="o">.</span><span class="n">loadDir</span><span class="p">,</span>
        <span class="s1">&#39;..&#39;</span><span class="p">,</span> <span class="s1">&#39;Icons&#39;</span><span class="p">,</span> <span class="s1">&#39;Tango&#39;</span><span class="p">,</span> <span class="s1">&#39;16x16&#39;</span><span class="p">,</span> <span class="s1">&#39;status&#39;</span><span class="p">,</span> <span class="n">icon</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">g</span><span class="o">.</span><span class="n">os_path_exists</span><span class="p">(</span><span class="n">fn</span><span class="p">):</span>
        <span class="n">c</span><span class="o">.</span><span class="n">editCommands</span><span class="o">.</span><span class="n">insertIconFromFile</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="n">fn</span><span class="p">)</span>
</pre></div>
</div>
<p>This deletes all icons of the node at position p:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">c</span><span class="o">.</span><span class="n">editCommands</span><span class="o">.</span><span class="n">deleteNodeIcons</span><span class="p">(</span><span class="n">p</span><span class="o">=</span><span class="n">p</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="ca-using-git">
<h4><a class="toc-backref" href="#id39">CA: using git</a><a class="headerlink" href="#ca-using-git" title="Permalink to this heading">¶</a></h4>
<p>Using Leo’s latest sources from GitHub is highly recommended. Once git is installed, the following gets the latest Leo sources:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">clone</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">github</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">leo</span><span class="o">-</span><span class="n">editor</span><span class="o">/</span><span class="n">leo</span><span class="o">-</span><span class="n">editor</span><span class="o">.</span><span class="n">git</span>
</pre></div>
</div>
<p>Thereafter, you can update Leo’s sources with:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">pull</span>
</pre></div>
</div>
<p>Git is great in tracking history and reverting unwanted changes. And it has many other benefits.</p>
<p>Using git is very similar to using bzr or hg or any other SCCS.  To change Leo, you add files, you commit files, and you push files.  That’s about it.</p>
</section>
<section id="ca-finding-nodes-with-c-clonefindbypredicate">
<h4><a class="toc-backref" href="#id40">CA: finding nodes with c.cloneFindByPredicate</a><a class="headerlink" href="#ca-finding-nodes-with-c-clonefindbypredicate" title="Permalink to this heading">¶</a></h4>
<p>c.cloneFindByPredicate is a powerful new addition to Leo.  Here is its docstring:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Traverse</span> <span class="n">the</span> <span class="n">tree</span> <span class="n">given</span> <span class="n">using</span> <span class="n">the</span> <span class="n">generator</span><span class="p">,</span> <span class="n">cloning</span> <span class="nb">all</span> <span class="n">positions</span> <span class="k">for</span>
<span class="n">which</span> <span class="n">predicate</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="ow">is</span> <span class="kc">True</span><span class="o">.</span> <span class="n">Undoably</span> <span class="n">move</span> <span class="nb">all</span> <span class="n">clones</span> <span class="n">to</span> <span class="n">a</span> <span class="n">new</span> <span class="n">node</span><span class="p">,</span> <span class="n">created</span>
<span class="k">as</span> <span class="n">the</span> <span class="n">last</span> <span class="n">top</span><span class="o">-</span><span class="n">level</span> <span class="n">node</span><span class="o">.</span> <span class="n">Returns</span> <span class="n">the</span> <span class="n">newly</span><span class="o">-</span><span class="n">created</span> <span class="n">node</span><span class="o">.</span> <span class="n">Arguments</span><span class="p">:</span>

<span class="n">generator</span><span class="p">,</span>      <span class="n">The</span> <span class="n">generator</span> <span class="n">used</span> <span class="n">to</span> <span class="n">traverse</span> <span class="n">the</span> <span class="n">tree</span><span class="o">.</span>
<span class="n">predicate</span><span class="p">,</span>      <span class="n">A</span> <span class="n">function</span> <span class="n">of</span> <span class="n">one</span> <span class="n">argument</span> <span class="n">p</span> <span class="n">returning</span> <span class="n">true</span> <span class="k">if</span>
                <span class="n">p</span> <span class="n">should</span> <span class="n">be</span> <span class="n">included</span><span class="o">.</span>
<span class="n">failMsg</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>   <span class="n">Message</span> <span class="n">given</span> <span class="k">if</span> <span class="n">nothing</span> <span class="n">found</span><span class="o">.</span> <span class="n">Default</span> <span class="ow">is</span> <span class="n">no</span> <span class="n">message</span><span class="o">.</span>
<span class="n">flatten</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>  <span class="kc">True</span><span class="p">:</span> <span class="n">Move</span> <span class="nb">all</span> <span class="n">node</span> <span class="n">to</span> <span class="n">be</span> <span class="n">parents</span> <span class="n">of</span> <span class="n">the</span> <span class="n">root</span> <span class="n">node</span><span class="o">.</span>
<span class="n">iconPath</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>  <span class="n">Full</span> <span class="n">path</span> <span class="n">to</span> <span class="n">icon</span> <span class="n">to</span> <span class="n">attach</span> <span class="n">to</span> <span class="nb">all</span> <span class="n">matches</span><span class="o">.</span>
<span class="n">redraw</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>    <span class="kc">True</span><span class="p">:</span> <span class="n">redraw</span> <span class="n">the</span> <span class="n">screen</span><span class="o">.</span>
<span class="n">undo_type</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">The</span> <span class="n">undo</span><span class="o">/</span><span class="n">redo</span> <span class="n">name</span> <span class="n">shown</span> <span class="ow">in</span> <span class="n">the</span> <span class="n">Edit</span><span class="p">:</span><span class="n">Undo</span> <span class="n">menu</span><span class="o">.</span>
                <span class="n">The</span> <span class="n">default</span> <span class="ow">is</span> <span class="s1">&#39;clone-find-predicate&#39;</span>
</pre></div>
</div>
<p>For example, clone-find-all-marked command is essentially:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@cmd</span><span class="p">(</span><span class="s1">&#39;clone-find-all-marked&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">cloneFindMarked</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">flatten</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">isMarked</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">p</span><span class="o">.</span><span class="n">isMarked</span><span class="p">()</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">cloneFindByPredicate</span><span class="p">(</span>
        <span class="n">generator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_unique_positions</span><span class="p">,</span>
        <span class="n">predicate</span> <span class="o">=</span> <span class="n">isMarked</span><span class="p">,</span>
        <span class="n">failMsg</span> <span class="o">=</span> <span class="s1">&#39;nothing found&#39;</span><span class="p">,</span>
        <span class="n">flatten</span> <span class="o">=</span> <span class="n">flatten</span><span class="p">,</span>
        <span class="n">undoType</span> <span class="o">=</span> <span class="s1">&#39;clone-find-marked&#39;</span><span class="p">,</span>
    <span class="p">)</span>
</pre></div>
</div>
<p>The predicate could filter on an attribute or <em>combination</em> of attributes. For example, the predicate could return p has attributes A and B but <em>not</em> attribute C. This instantly gives Leo full database query capabilities. If we then hoist the resulting node we see <em>all and only</em> those nodes satisfying the query.</p>
<p>These following position methods make it easy to skip &#64;ignore trees or &#64;&lt;file&gt; trees containing &#64;all:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">p</span><span class="o">.</span><span class="n">is_at_all</span><span class="p">()</span>          <span class="kc">True</span> <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="n">an</span> <span class="o">@&lt;</span><span class="n">file</span><span class="o">&gt;</span> <span class="n">node</span> <span class="n">containing</span> <span class="n">an</span> <span class="nd">@all</span> <span class="n">directive</span><span class="o">.</span>
<span class="n">p</span><span class="o">.</span><span class="n">in_at_all</span><span class="p">()</span>          <span class="kc">True</span> <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="ow">in</span> <span class="n">an</span> <span class="o">@&lt;</span><span class="n">file</span><span class="o">&gt;</span> <span class="n">tree</span> <span class="n">whose</span> <span class="n">root</span> <span class="n">contains</span> <span class="nd">@all</span><span class="o">.</span>
<span class="n">p</span><span class="o">.</span><span class="n">is_at_ignore</span><span class="p">()</span>       <span class="kc">True</span> <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="n">an</span> <span class="nd">@ignore</span> <span class="n">node</span>
<span class="n">p</span><span class="o">.</span><span class="n">in_at_ignore_tree</span><span class="p">()</span>  <span class="kc">True</span> <span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="ow">in</span> <span class="n">an</span> <span class="nd">@ignore</span> <span class="n">tree</span><span class="o">.</span>
</pre></div>
</div>
<p>For example, here is how to gather only those marked nodes that lie outside any &#64;ignore tree:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">isMarked</span><span class="p">(</span><span class="n">p</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">p</span><span class="o">.</span><span class="n">isMarked</span><span class="p">()</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">p</span><span class="o">.</span><span class="n">in_at_ignore_tree</span><span class="p">()</span>

<span class="n">c</span><span class="o">.</span><span class="n">cloneFindByPredicate</span><span class="p">(</span>
    <span class="n">generator</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">all_unique_positions</span><span class="p">,</span>
    <span class="n">predicate</span> <span class="o">=</span> <span class="n">isMarked</span><span class="p">,</span>
    <span class="n">flatten</span> <span class="o">=</span> <span class="n">flatten</span><span class="p">,</span>
    <span class="n">undoType</span> <span class="o">=</span> <span class="s1">&#39;gather-marked&#39;</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
</section>
</section>
<section id="leo-university">
<h3><a class="toc-backref" href="#id41">Leo University</a><a class="headerlink" href="#leo-university" title="Permalink to this heading">¶</a></h3>
<p>Leo University is a project devoted to help people become Leo developers.</p>
<p>Here is the main page.  It contains links to individual lessons.
<a class="reference external" href="https://github.com/leo-editor/leo-editor/issues/816">https://github.com/leo-editor/leo-editor/issues/816</a></p>
</section>
<section id="architecture">
<h3><a class="toc-backref" href="#id42">Architecture</a><a class="headerlink" href="#architecture" title="Permalink to this heading">¶</a></h3>
<p>Leo uses a model/view/controller architecture.</p>
<ul class="simple">
<li><p>Controller: The Commands class and its helpers in leoCommands.py and leoEditCommands.py.</p></li>
<li><p>Model: The VNode and Position classes in leoNodes.py.</p></li>
<li><p>View: The gui-independent base classes are in the node “Gui Base Classes”. The Qt-Specific subclasses are in the node “Qt gui”.</p></li>
</ul>
<p><strong>Important</strong>: The general organization of these classes have changed hardly at all in Leo’s 20+ year history.  The reason is that what each class does is fairly obvious.  How the gets the job done may have changed drastically, but <em>that’s an internal implementation detail of the class itself</em>.  This is the crucial design principle that allows Leo’s code to remain stable.  <em>Classes do not know or meddle in the internal details of other classes</em>.  As a result, nobody, including EKR, needs to remember internal details.</p>
</section>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="leo_toc.html">
              <img class="logo" src="_static/LeoLogo.svg" alt="Logo"/>
            </a></p>
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="FAQ.html"
                          title="previous chapter">FAQ</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="slides.html"
                          title="next chapter">Slides</a></p>
  </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>

      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="slides.html" title="Slides"
             >next</a> |</li>
        <li class="right" >
          <a href="FAQ.html" title="FAQ"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="leo_toc.html">Leo 6.7.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="toc-more-links.html" >More Leo Links</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Leo’s Cheat Sheet</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 1997-2023, Edward K. Ream.
      Last updated on February 28, 2023.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
    </div>
  </body>
</html>